function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var t, e = function(a) {
    return a && a.__esModule ? a : {
        default: a
    };
}(require("../../../components/toast/toast")), o = getApp(), s = require("../../../utils/util.js");

Page({
    data: {
        value3: "1",
        value2: "",
        selectYear: 1,
        yearIshidden: !1,
        isCard: 0,
        iscoupons: 0,
        couponIscan: !1,
        isUse: "不可用",
        showState: 1500505
    },
    onLoad: function(a) {
        t = this, void 0 !== a.shopId && this.setData({
            shopId: a.shopId
        }), t.getServiceInfo(), t.getAutoService(), t.getYearIsHidden(), t.getCanuseCoupons();
        var e = wx.getStorageSync("kScreenW");
        t.setData({
            width: e,
            pre3_shop_left: 30 * e,
            pre3_shop_left1: 28 * e
        });
    },
    onChange3: function(a) {
        this.onChange("value3", a);
        var e = t.data.autoList;
        2 == a.detail.value && 6 == t.data.shopId || 3 == a.detail.value && 6 == t.data.shopId ? e.forEach(function(a) {
            100 * a.price > 1e3 && 0 == a.isCard.indexOf("1") && (a.price = s.convertMath(100 * a.price - 1e3), 
            t.setData({
                autoList: e
            }));
        }) : t.getAutoService(!0);
    },
    onChange: function(t, e) {
        this.setData(a({}, t, e.detail.value));
    },
    next: function(a) {
        var n = o.globalData.token, d = t.data.value3;
        6 == t.data.selectYear ? (t.showLoadingToast(), s.request(o, "wx/cust/insertAutoWashOrders", "POST", {
            token: n,
            shopId: t.data.shopId,
            bizShopPackage: t.data.value2
        }, function(a) {
            a.state && (0 == t.data.showState ? t.toPay(a.data.serviceOrderId) : (e.default.clear(), 
            wx.showToast({
                title: "服务暂停",
                icon: "none"
            })));
        }, function(a) {})) : wx.request({
            url: o.globalData.url + "wx/car/machineIsReady",
            data: {
                token: n,
                shopId: t.data.shopId
            },
            success: function(a) {
                a.data.state ? wx.request({
                    url: o.globalData.url + "wx/fbox/getParkState",
                    data: {
                        token: n,
                        shopId: t.data.shopId
                    },
                    success: function(a) {
                        a.data.state ? wx.request({
                            url: o.globalData.url + "wx/fbox/getParkState",
                            data: {
                                token: n,
                                shopId: t.data.shopId
                            },
                            success: function(a) {
                                a.data.state ? "1" == d ? (t.showLoadingToast(), s.request(o, "wx/cust/insertAutoWashOrders", "POST", {
                                    token: n,
                                    shopId: t.data.shopId,
                                    bizShopPackage: t.data.value2
                                }, function(a) {
                                    a.state && (0 == t.data.showState ? t.toPay(a.data.serviceOrderId) : (e.default.clear(), 
                                    wx.showToast({
                                        title: "服务暂停",
                                        icon: "none"
                                    })));
                                }, function(a) {})) : "2" == d ? -1 == t.data.isCard ? wx.showToast({
                                    title: "当前无法使用年卡",
                                    icon: "none"
                                }) : s.request(o, "wx/cust/getIsCardTwices", "GET", {
                                    token: n,
                                    shopId: t.data.shopId
                                }, function(a) {
                                    a.state ? null == a.data || 0 == a.data.length ? s.request(o, "wx/biz/getWxBizCard", "GET", {
                                        token: n,
                                        shopId: t.data.shopId
                                    }, function(a) {
                                        a.state && (null == a.data ? wx.showToast({
                                            title: "该门店无法购买年卡",
                                            icon: "none"
                                        }) : (t.record.pauseMuisc(), wx.navigateTo({
                                            url: "../vipCard/index?shopId=" + t.data.shopId
                                        })));
                                    }, function(a) {}) : 6 == t.data.shopId && 6 != t.data.value2 ? (t.showLoadingToast(), 
                                    s.request(o, "wx/cust/insertAutoWashOrder", "POST", {
                                        token: n,
                                        shopId: t.data.shopId,
                                        bizShopPackage: t.data.value2
                                    }, function(a) {
                                        a.state && t.toPay(a.data.serviceOrderId);
                                    }, function(a) {})) : s.request(o, "wx/cust/insertAutoWashOrder", "POST", {
                                        token: n,
                                        shopId: t.data.shopId,
                                        bizShopPackage: t.data.value2
                                    }, function(a) {
                                        a.state && s.request(o, "wx/fbox/commonWash", "GET", {
                                            token: n,
                                            shopId: t.data.shopId
                                        }, function(e) {
                                            e.state ? (s.request(o, "wx/car/orderSaveRedis", "POST", {
                                                token: n,
                                                orderServiceId: a.data.serviceOrderId,
                                                shopId: t.data.shopId
                                            }, function(a) {}, function(a) {}), s.request(o, "wx/cust/yearCardUpdateState", "GET", {
                                                token: n,
                                                serviceOrderId: a.data.serviceOrderId,
                                                shopId: t.data.shopId
                                            }, function(a) {
                                                a.state;
                                            }, function(a) {}), t.record.pauseMuisc(), wx.redirectTo({
                                                url: "../start/start?shopId=" + t.data.shopId + "&serviceOrderId=" + a.data.serviceOrderId
                                            })) : wx.showToast({
                                                title: "请根据语音提示停好车辆",
                                                icon: "none"
                                            });
                                        }, function(a) {});
                                    }, function(a) {}) : wx.showToast({
                                        title: "无法购买年卡",
                                        icon: "none"
                                    });
                                }, function(a) {}) : "3" == d && (6 == t.data.shopId && 6 != t.data.value2 ? (t.showLoadingToast(), 
                                s.request(o, "wx/cust/insertAutoWashForFrees", "POST", {
                                    token: n,
                                    shopId: t.data.shopId,
                                    bizShopPackage: t.data.value2
                                }, function(a) {
                                    a.state && t.toPay(a.data.serviceOrderId);
                                }, function(a) {})) : s.request(o, "wx/cust/insertAutoWashForFree", "POST", {
                                    token: n,
                                    shopId: t.data.shopId,
                                    bizShopPackage: t.data.value2
                                }, function(a) {
                                    a.state && s.request(o, "wx/fbox/commonWash", "GET", {
                                        token: n,
                                        shopId: t.data.shopId
                                    }, function(d) {
                                        d.state ? (s.request(o, "wx/car/orderSaveRedis", "POST", {
                                            token: n,
                                            orderServiceId: a.data.serviceOrderId,
                                            shopId: t.data.shopId
                                        }, function(a) {}, function(a) {}), t.record.pauseMuisc(), wx.redirectTo({
                                            url: "../start/start?shopId=" + t.data.shopId + "&serviceOrderId=" + a.data.serviceOrderId
                                        })) : (e.default.clear(), wx.showToast({
                                            title: "请根据语音提示停好车辆",
                                            icon: "none"
                                        }));
                                    }, function(a) {});
                                }, function(a) {})) : (e.default.clear(), wx.showToast({
                                    title: "请根据语音提示停好车辆",
                                    icon: "none"
                                }));
                            }
                        }) : (e.default.clear(), wx.showToast({
                            title: "请根据语音提示停好车辆",
                            icon: "none"
                        }));
                    }
                }) : wx.showToast({
                    title: a.data.message,
                    icon: "none"
                });
            }
        });
    },
    toPay: function(a) {
        o.globalData.token;
        wx.request({
            url: o.globalData.url + "wx/pay/info",
            data: s.json2Form({
                token: o.globalData.token,
                orderId: a,
                couponId: "",
                payType: 2
            }),
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            method: "POST",
            success: function(n) {
                if (e.default.clear(), n.data.state) {
                    var d = n.data.data;
                    wx.requestPayment({
                        timeStamp: d.timeStamp,
                        nonceStr: d.nonceStr,
                        package: d.packageValue,
                        signType: d.signType,
                        paySign: d.paySign,
                        success: function(e) {
                            t.record.pauseMuisc(), 6 != t.data.selectYear ? wx.redirectTo({
                                url: "../start/start?shopId=" + t.data.shopId + "&serviceOrderId=" + a
                            }) : (wx.switchTab({
                                url: "/pages/service/index"
                            }), wx.setStorageSync("service", 1));
                        },
                        fail: function(a) {
                            "requestPayment:fail cancel" == a.errMsg && (wx.showToast({
                                title: "已取消订单"
                            }), wx.request({
                                url: o.globalData.url + "wx/pay/cancel",
                                data: s.json2Form({
                                    token: o.globalData.token,
                                    payId: d.payId
                                }),
                                header: {
                                    "Content-Type": "application/x-www-form-urlencoded"
                                },
                                method: "POST",
                                success: function(a) {},
                                fail: function(a) {}
                            }));
                        }
                    });
                } else wx.showToast({
                    title: "发起支付失败:" + n.data.message
                });
            }
        });
    },
    getServiceInfo: function() {
        var a = o.globalData.token;
        s.request(o, "wx/biz/getBizShopDetail", "POST", {
            token: a,
            shopId: t.data.shopId
        }, function(a) {
            a.state && t.setData({
                shopName: a.data.shopName
            });
        }, function(a) {});
    },
    getAutoService: function(a) {
        var e = o.globalData.token;
        s.request(o, "wx/biz/getServiceByShopAutoWash", "GET", {
            token: e,
            shopId: t.data.shopId
        }, function(e) {
            if (e.state) {
                var o = e.data;
                if (t.setData({
                    selectYear: e.data[0].packageId
                }), o.forEach(function(a) {
                    return a.price = s.convertMath(a.price);
                }), t.setData({
                    autoList: o
                }), 1 != a) {
                    var n = 0;
                    do {
                        0 != o[n].showState ? (n++, t.setData({
                            value2: o[n].bizShopPackage,
                            showState: o[n].showState,
                            isCard: o[n].isCard.indexOf("1"),
                            iscoupons: o[n].isCard.indexOf("3")
                        })) : t.setData({
                            value2: o[n].bizShopPackage,
                            showState: o[n].showState,
                            isCard: o[n].isCard.indexOf("1"),
                            iscoupons: o[n].isCard.indexOf("3")
                        });
                    } while (0 != o[n].showState && o.length - 1 > n);
                }
            }
        }, function(a) {});
    },
    onChange2: function(a) {
        this.onChange("value2", a), t.getYearIsHidden(), t.data.autoList.forEach(function(e) {
            if (a.detail.value === e.bizShopPackage) {
                var o = e.isCard;
                t.setData({
                    showState: e.showState,
                    selectYear: e.packageId,
                    isCard: o.indexOf("1"),
                    iscoupons: o.indexOf("3")
                });
            }
        }), -1 != t.data.isCard ? t.setData({
            value3: "2"
        }) : -1 != t.data.iscoupons && t.data.couponIscan ? -1 != t.data.isCard ? t.setData({
            value3: "2"
        }) : t.setData({
            value3: "3"
        }) : t.setData({
            value3: "1"
        });
    },
    getYearIsHidden: function() {
        var a = o.globalData.token;
        s.request(o, "wx/biz/getShopCanUseCard", "GET", {
            token: a,
            shopId: t.data.shopId
        }, function(a) {
            a.state ? t.setData({
                yearIshidden: !1
            }) : t.setData({
                yearIshidden: !0
            });
        }, function(a) {});
    },
    onReady: function() {
        this.record = this.selectComponent("#record");
    },
    getCanuseCoupons: function() {
        var a = o.globalData.token;
        s.request(o, "wx/mkt/getWashCouponCanUse", "GET", {
            token: a
        }, function(a) {
            a.state && null != a.data && a.data.length > 0 && a.data[0].couponNum > 0 && t.setData({
                couponIscan: !0,
                couponWashName: a.data[0].couponWashName
            }), -1 != t.data.isCard ? t.setData({
                value3: "2"
            }) : -1 != t.data.iscoupons && t.data.couponIscan ? -1 != t.data.isCard ? t.setData({
                value3: "2"
            }) : t.setData({
                value3: "3"
            }) : t.setData({
                value3: "1"
            });
        }, function(a) {});
    },
    onUnload: function() {
        this.record.pauseMuisc();
    },
    onHide: function() {
        this.record.pauseMuisc();
    },
    showLoadingToast: function() {
        e.default.loading({
            mask: !0,
            message: "检测环境..."
        });
    }
});